package com.roger.bt.trans.ser;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class BtClient extends BtBase {
    private Executor EXECUTOR = Executors.newCachedThreadPool();
    public BtClient(Listener listener) {
       super(listener);
    }

    public void connect(BluetoothDevice dev) {
        close();
        try {
            final BluetoothSocket socket = dev.createInsecureRfcommSocketToServiceRecord(SPP_UUID);
            EXECUTOR.execute(new Runnable() {
                @Override
                public void run() {
                    loopRead(socket);
                }
            });
        } catch (Throwable e) {
            close();
        }
    }



}